package org.cainiao.basic.collection.listqueue;

import java.util.*;

public class RemoveTest {

    public static void main(String[] args) {
        List<Map<String, Object>> list = new ArrayList<>();
        list.add(getRow(1));
        list.add(getRow(2));
        list.add(getRow(3));
        list.add(getRow(4));

        double mergeValue = 0;
        int rest = 2;
        Iterator<Map<String, Object>> iterator = list.iterator();
        int i = 0;
        while (iterator.hasNext()) {
            Map<String, Object> row = iterator.next();
            if (i >= rest) {
                Object valueObject = row.get("value");
                mergeValue += valueObject == null
                    ? 0 : Double.parseDouble(valueObject.toString());
                iterator.remove();
            }
            i++;
        }


        System.out.println(mergeValue);
        System.out.println(list);
    }

    private static Map<String, Object> getRow(double value) {
        Map<String, Object> row = new HashMap<>();
        row.put("value", value);
        return row;
    }

}
